package org.test.huoche;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.mysql.jdbc.TimeUtil;

public class RefreshSession implements Runnable {
    /**
     * 刷新SESSION地址
     */
    private final static String REFRESH_SESSION_URL = "https://dynamic.12306.cn/otsweb/order/myOrderAction.do?method=queryMyOrderNotComplete";

    private ResponseEntity responseEntity = null;

    /**
     * @return the responseEntity
     */
    public ResponseEntity getResponseEntity() {
        return responseEntity;
    }

    /**
     * @param responseEntity
     *            the responseEntity to set
     */
    public void setResponseEntity(ResponseEntity responseEntity) {
        this.responseEntity = responseEntity;
    }

    @Override
    public void run() {
        try {
            do {
                Map<String, String> requestHeaders = new HashMap<String, String>();
                //设置请求头
                requestHeaders.put("Cookie",
                        "JSESSIONID=8D5EB3FD198B05DA80F20546685E63E6; BIGipServerotsweb=2631139594.48160.0000");
                requestHeaders.put("Cache-Control", "no-cache");
                requestHeaders.put("Connection", "Keep-Alive");
                requestHeaders.put("Accept-Language", "zh-cn");
                requestHeaders
                        .put("User-Agent",
                                "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; InfoPath.2; 360SE)");
                System.out.println("----刷新页面保持session----");
                Test.request(REFRESH_SESSION_URL, false, "refresh.html", null, requestHeaders, null);
                TimeUnit.MINUTES.sleep(5);
            } while (true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
